#define _CRT_SECURE_NO_WARNINGS
#include"Queue.h"
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->size = 0;
	pq->phead = pq->ptail = NULL;
}
void QueueDestroy(Queue* pq)
{
	if (pq->phead)
	{
		QNode* arr = pq->phead;
		while (arr!=pq->ptail)
		{
			QNode* ass =arr->next;
			free(arr);
			arr = ass;
		}
		free(arr);
		arr = NULL;
		pq->phead = pq->ptail = 0;
	}
}
void QueuePush(Queue* pq, QDataType x)
{
	assert(pq);
	QNode* arr = (QNode*)malloc(sizeof(QNode));
	if (arr == NULL)
	{
		perror("malloc arr");
		return;
	}
	arr->next = x;
	arr->next = NULL;
	if (pq->phead == NULL)
	{
		pq->phead = pq->ptail = arr;
	}
	else
	{
		pq->ptail->next = arr;
		pq->ptail = arr;
	}
	pq->size++;
}
int QueueSize(Queue* pq)
{
	assert(pq);
	return pq->size;
}
void QueuePop(Queue* pq)
{
	assert(pq&&pq->size);
	if (pq->phead == pq->ptail)
	{
		free(pq->phead);
		pq->phead = pq->ptail = NULL;
	}
	else
	{
		QNode* arr = pq->phead->next;
		free(pq->phead);
		pq->phead = arr;
	}
	pq->size--;
}
QDataType QueueFront(Queue* pq)
{
	assert(pq);
	assert(pq->size);
	return pq->phead->val;
}
QDataType QueueBack(Queue* pq)
{
	assert(pq);
	assert(pq->size);
	return pq->ptail->val;
}
bool QueueEmpty(Queue* pq)
{
	assert(pq);
	return pq->size == 0;
}